

var tradeAreaId = getvl("id");
//商圈
TradeArea();

var currentPage = 1;


//列表
loadMyEssay(tradeAreaId);

function loadMyEssay(tradeAreaId) {
	$(document).ready(function() {
		init(currentPage);
	});

	function init(pageNo) {
		$("#areaList").html("");
		$.ajax({
			url: urlcore + "/api/tradeArea/selectTradeShopGoodsList?id=" + tradeAreaId + "&current=" + pageNo,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					$.each(data.data.list, function(i, n) {
						var shop = '';
						$.each(n.shopInfoList, function(i, m) {
							var goods = '';
							$.each(m.goodsList, function(i, c) {
								var coverUrl=c.coverUrl==null?'http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/default.png':c.coverUrl;
                                coverUrl=isHasImg(coverUrl);
                                var tradePrice=n.tradePrice==null?"0":n.tradePrice;
								
								goods +=
									'<li>' +
									'<img class="searchGoodsImgs" src="' + coverUrl + '" />' +
									'<h5>&yen;' + tradePrice + '</h5>' +
									'</li>';

							});
							if(goods==''){
								goods='<div style="padding:118px 0px 0px 137px;color:gray;">~ ~ ~ 暂无 商品 ~ ~ ~</div>';
							}
							
							var headImg=m.headImg==null?"http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/sqz.png":m.headImg;
							headImg=isHasImg(headImg);
							var storeName=m.storeName==null?"":m.storeName;
							var monthNew=m.monthNew==null?"":m.monthNew;
							var province=m.province==null?"":m.province;
							var city=m.city==null?"":m.city;
							var areaName=m.areaName==null?"":m.areaName;
							
							shop +=
							'<div class="shangquan_goods">' +
							'<a target="_blank" href="10.1.0dianpu_detail.html?id='+m.id+'&type=3">' +
							'<ul class="clearfix">' + goods +
							'</ul>' +
							'<div class="shangquan_xinxi">' + 
							'<h6><img src="' + headImg + '" />' + storeName + '</h6>' +
								'<p>最新: ' + monthNew + ' 更新时间: ' + new Date(m.operateTime).pattern("HH:mm") + '</p>' +
								'<p>' + province + '-' + city + '-' + areaName + '</p>'+
							'</div>' +
							'</a>' +
							'</div>';
						});
                        var areaUrl=n.areaUrl==null?'http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/default.png':n.areaUrl;
                        areaUrl=isHasImg(areaUrl);
                        var areaName=n.areaName==null?"":n.areaName;
                        var price=n.price==null?"":n.price;
                        var newGoods=n.newGoods==null?"0":n.newGoods;
                        var characteristic=n.characteristic==null?"":n.characteristic;
                        var briefIntroduction=n.briefIntroduction==null?"":n.briefIntroduction;
						var thislist =
							'<div class="shangquan_jieshao">' +
							'<dl class="clearfix">' +
							'<dt>' +
							'<img class="searchAreaUrlImg" src="' + areaUrl + '" />' +
							'</dt>' +
							'<dd>' +
							'<h5>' + areaName + '</h5>' +
							'<p>' +
							'<span>商品均价:</span>' +
							'<em>&yen;' + price + '</em>' +
							'</p>' +
							'<p>' +
							'<span>本月更新:</span>' +
							'<em>' + newGoods + '</em>' +
							'</p>' +
							'<p><span>商圈特色: </span>' + characteristic + '</p>' +
							'<p><span>商圈简介: </span>' + briefIntroduction + ' </p>' +
							'</dd>' +
							'</dl>' +
							'</div>' +
							'<div class="clearfix" style="margin-left: -15px;">'
							+shop+
							'</div>';
						$('#areaList').append(thislist);
					});
					
					    //固定宽高
						$(function(){
							
							var imgList = document.getElementsByClassName("searchGoodsImgs");  
						    var w=124;
						    var h=124;
						    for(var i=0;i<imgList.length;i++){
						        if(imgList[i].width>w || imgList[i].height>h){  
						            imgList[i].width = w;  
						            imgList[i].heigth = h;  
						        }  
						    }  
							
							
							var imgList1 = document.getElementsByClassName("searchAreaUrlImg");  
						    var w1=220;
						    var h1=220;
						    for(var i=0;i<imgList1.length;i++){
						        if(imgList1[i].width>w1 || imgList1[i].height>h1){  
						            imgList1[i].width = w1;  
						            imgList1[i].heigth = h1;  
						        }  
						    }  
						    
						})

					$("#pager").pager({
						pagenumber: pageNo,
						pagecount: data.data.pages,
						totalcount: data.data.total,
						buttonClickCallback: PageClick
					});

				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					//alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						layer.alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				layer.alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}

//按区域查询
function searchByTradeArea(tradeAreaId) {
	loadMyEssay(tradeAreaId);
}
 